import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('localhost',1028))
s.listen(1)

try:
    while True:
        client, address = s.accept()
        data = client.recv(1024)
        client.send(data)
        client.close()
finally:
    s.close()
